package com.stephen.kafka;

import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.UUID;

@Component
@Slf4j
public class Sender {
    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    public void send() {
        Message msg = new Message();
        msg.setId(System.currentTimeMillis());
        msg.setMsg(UUID.randomUUID().toString() + "中国");
        msg.setSendTime(new Date());
        log.info("send message = {}",new Gson().toJson(msg));
        kafkaTemplate.send("topic_test",new Gson().toJson(msg));
    }
}